package cn.shentianlan.service.impl;

import cn.shentianlan.domain.dto.TeacherCourseDTO;
import cn.shentianlan.domain.entity.TeacherCourse;
import cn.shentianlan.mapper.TeacherCourseMapper;
import cn.shentianlan.service.TeacherCourseService;
import cn.shentianlan.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 陈俊源
 * @Description TODO
 * @Date 2021/5/4
 * @Version 1.0
 */
@Service
public class TeacherCourseServiceImpl implements TeacherCourseService {

    @Autowired
    private TeacherCourseMapper teacherCourseMapper;

    @Override
    public Result save(TeacherCourseDTO teacherCourseDTO) {
        if (teacherCourseDTO == null){
            return Result.fail("参数对象为空，无法新增课程");
        }
        if (teacherCourseDTO.getCourseId()==null ||teacherCourseDTO.getTeacherId()==null ){
            return Result.fail("传入数据出错，无法新增课程");
        }
        TeacherCourse teacherCourse = teacherCourseMapper.getTeacherCourse(teacherCourseDTO);
        if (teacherCourse!=null){
            return Result.fail("该课程已存在，请勿重复添加");
        }
        teacherCourseMapper.save(teacherCourseDTO);
        return Result.success();
    }

    @Override
    public Result delete(TeacherCourseDTO teacherCourseDTO) {
        if (teacherCourseDTO == null){
            return Result.fail("参数对象为空，无法删除课程");
        }
        if (teacherCourseDTO.getCourseId()==null ||teacherCourseDTO.getTeacherId()==null ){
            return Result.fail("传入数据出错，无法删除课程");
        }
        TeacherCourse teacherCourse = teacherCourseMapper.getTeacherCourse(teacherCourseDTO);
        if (teacherCourse==null){
            return Result.fail("该课程不存在，无法删除");
        }
        teacherCourseMapper.delete(teacherCourseDTO);
        return Result.success();
    }


}
